package com.lq.util;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

public class CookieUtil {

    public static HashMap<String, String> getNameAndPwd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HashMap<String,String> map = new HashMap<>();

        Cookie[] cookies = req.getCookies();

        boolean flag = false;

        String username = "";
        String password = "";
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("autologinName")){
                    username = cookie.getValue();
                    map.put("username",username);
                }

                if (cookie.getName().equals("autologinPassword")){
                    password = cookie.getValue();
                    map.put("password",password);
                    map.put("checked","checked");
                }
            }
        }

        return map;
    }
}
